package com.hanfb.mall.inventory.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hanfb.mall.inventory.dao.RedisDao;
import com.hanfb.mall.inventory.mapper.UserMapper;
import com.hanfb.mall.inventory.model.User;
import com.hanfb.mall.inventory.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.net.UnknownServiceException;

/**
 * @作者： Hanfb
 * @描述：
 * @时间： 2020年09月24日
 */
@Service
public class UserServiceImpl  implements UserService {

    @Resource
    UserMapper userMapper;

    @Autowired
    RedisDao redisDao;

    @Override
    public User findUser() {
        System.out.println(userMapper.findUserInfo());

        return userMapper.findUserInfo();
    }

    @Override
    public User getCachedUser() {

        redisDao.set("cached_user_lisi","{\"name\":\"lisi\",\"age\":28}");

        String userJson=redisDao.get("cached_user_lisi");
        JSONObject userJsonObject = JSONObject.parseObject(userJson);
        User user=new User();

        user.setName(userJsonObject.getString("name"));
        user.setAge(userJsonObject.getInteger("age"));
        return user;
    }
}
